home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / macforma.0 / macforma / macformat / getdiskblocks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-17  |  1.8 KB  |  72 lines

  1. /***********************************************************
  2. *  getdiskblocks.c -- read disk blocks and write to file   *
  3. *----------------------------------------------------------*
  4. *  ⌐1995 Artsoft Development                               *
  5. *        Holger Schemel                                    *
  6. *        33659 Bielefeld-Senne                             *
  7. *        Telefon: (0521) 493245                            *
  8. *        eMail: aeglos@valinor.owl.de                      *
  9. *               aeglos@uni-paderborn.de                    *
  10. *               q99492@pbhrzx.uni-paderborn.de             *
  11. ***********************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <fcntl.h>
  16.  
  17. #include "global.h"
  18.  
  19. unsigned char blocks1[BLOCKCOUNT1*BLOCKSIZE];
  20. unsigned char blocks2[BLOCKCOUNT2*BLOCKSIZE];
  21.  
  22. void GetDiskBlocks(char *, char *, unsigned char *, int, int);
  23.  
  24. int main(int argc, char **argv)
  25. {
  26.   char progname[1024];
  27.  
  28.   strcpy(progname,GetFilename(argv[0]));
  29.  
  30.   if (argc!=2)
  31.   {
  32.     fprintf(stderr,"Usage: %s <disk device>\n",progname);
  33.     exit(-1);
  34.   }
  35.  
  36.   GetDiskBlocks(argv[1],FILE1,blocks1,BLOCKOFFSET1,BLOCKCOUNT1);
  37.   GetDiskBlocks(argv[1],FILE2,blocks2,BLOCKOFFSET2,BLOCKCOUNT2);
  38.  
  39.   exit(0);
  40. }
  41.  
  42. void GetDiskBlocks(char *device, char *file,
  43.           unsigned char *blocks, int offset, int count)
  44. {
  45.   int fd_device, fd_file;
  46.  
  47.   if ((fd_device=open(device,O_RDONLY))<0)
  48.   {
  49.     perror(device);
  50.     exit(-1);
  51.   }
  52.   lseek(fd_device, offset*BLOCKSIZE, SEEK_SET);
  53.   if (read(fd_device, blocks, count*BLOCKSIZE)!=count*BLOCKSIZE)
  54.   {
  55.     perror(device);
  56.     exit(-1);
  57.   }
  58.   close(fd_device);
  59.  
  60.   if ((fd_file=open(file,O_CREAT | O_WRONLY,0666))<0)
  61.   {
  62.     perror(file);
  63.     exit(-1);
  64.   }
  65.   if (write(fd_file, blocks, count*BLOCKSIZE)!=count*BLOCKSIZE)
  66.   {
  67.     perror(file);
  68.     exit(-1);
  69.   }
  70.   close(fd_file);
  71. }
  72.